package com.ww.microrpc.netty.protocol;

import com.ww.microrpc.netty.Constant;
import com.ww.microrpc.netty.handler.client.SendCallback;

import java.util.Arrays;

public class RequestMessage implements Message {
    /**
     * 请求ID
     */
    private int requestId;

    /**
     * 类名
     */
    private String className;

    /**
     * 方法名
     */
    private String methodName;

    /**
     * 参数类型列表
     */
    private Class<?>[] parameterTypes;

    /**
     * 参数列表
     */
    private Object[] parameters;

    private transient SendCallback callback;

    public RequestMessage(){}

    public RequestMessage(int requestId, String className, String methodName, Class<?>[] parameterTypes, Object[] parameters) {
        this.requestId = requestId;
        this.className = className;
        this.methodName = methodName;
        this.parameterTypes = parameterTypes;
        this.parameters = parameters;
    }

    public int getRequestId() {
        return requestId;
    }

    public void setRequestId(int requestId) {
        this.requestId = requestId;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public Class<?>[] getParameterTypes() {
        return parameterTypes;
    }

    public void setParameterTypes(Class<?>[] parameterTypes) {
        this.parameterTypes = parameterTypes;
    }

    public Object[] getParameters() {
        return parameters;
    }

    public void setParameters(Object[] parameters) {
        this.parameters = parameters;
    }

    @Override
    public int getMessageType() {
        return Constant.MessageType.RequestMessage;
    }

    @Override
    public String toString() {
        return "RequestMessage{" +
                "requestId='" + requestId + '\'' +
                ", className='" + className + '\'' +
                ", methodName='" + methodName + '\'' +
                ", parameterTypes=" + Arrays.toString(parameterTypes) +
                ", parameters=" + Arrays.toString(parameters) +
                '}';
    }

    public SendCallback getCallback() {
        return callback;
    }

    public void setCallback(SendCallback callback) {
        this.callback = callback;
    }

    public boolean isSync() {
        return false;
    }
}
